<template>
	<view class="ticket-detail-page">
		<view class="wrap">
			<view class="ticket-list">
        <view class="ticket-title">
        	<text class="title">{{ info.commonName }}</text>
        	<view class="name"><text>{{ info.ticketName }}</text><text>{{ info.detaildVoList.length }}张</text></view>
          <view class="ticket-validity" v-if="info.detaildVoList.length > 0">
            {{info.detaildVoList[0].ticketUsetimeStart}}
            <text class="tcan">至</text>
            {{info.detaildVoList[0].ticketUsetimeEnd}}
            <text class="tcan">可用</text>
          </view>
        </view>
				<view class="ticket-item">
					<view class="ticket-card" v-for="it in info.detaildVoList || []" :key="it.orderDetailsId">
						<view class="item" >
							<view class="value">{{ it.identityName }}</view>
						</view>
					  <view class="item" v-if="it.identityDocumentDetails">
					  	<view class="label">身份证号</view>
					  	<view class="value"> {{ it.identityDocumentDetails }} </view>
					  </view>
						<view class="item" v-if="it.identityPhone">
							<view class="label">手机号</view>
							<view class="value"> {{ it.identityPhone }} </view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!--  按钮      -->
		<view class="btns" :style="{bottom: (GET_SAFEAREA_BOTTOM > 0 ? GET_SAFEAREA_BOTTOM : 34) +'px'}">
			<block>
				<view class="btn primary w422" @click.stop="handleTicket(id)">确认核销</view>
			</block>
		</view>
	</view>
</template>

<script>
	import commonHeader from "@/components/commonHeader.vue";
	import tkiQrcode from "tki-qrcode";
	import uniPopup from "@/components/uni-popup/uni-popup.vue";
	import requestPost, {
		requestGet
	} from "@/utils/request";
	import {
		ticketOrderStatus
	} from "@/utils/constant";
	import {
		throttle
	} from '@/utils/index.js'
  import store, { GET_SAFEAREA_BOTTOM } from '../../store/index.js';
  import {mapGetters} from 'vuex'
  import dayjs from "dayjs";
	export default {
		components: {
			commonHeader,
			tkiQrcode,
			uniPopup
		},
		props: ["id", "type"],
		data() {
			return {
				info: {},
			};
		},
    computed: {
    	...mapGetters([GET_SAFEAREA_BOTTOM])
    },
		onShow() {
      console.log('安全区距离', this.GET_SAFEAREA_BOTTOM);
			if (this.id) {
				console.log('验票id', this.id)
				this.getDetail();
			}
		},
		methods: {
			handleTicket() {
				let api;
				if (this.type == 'jq') {
					api = `/order/scenicTicketBusinessOrder/ticCheckStatus/${this.id}`
				} else if (this.type == 'act') {
					api = `/order/activityTicketBusinessOrder/ticCheckStatus/${this.id}`
				}
				requestGet(api)
					.then((check) => {
						uni.showModal({
							title: '提示',
							content: check.code == 200 ? '核销成功，是否继续核销？' : '核销异常，是否重试？',
							showCancel: true,
							cancelText: '不了',
							confirmText: check.code == 200 ? '继续核销' : '重新核销',
							success: function(res) {
								if (res.confirm) {
									uni.navigateBack()
								} else if (res.cancel) {
									console.log('用户点击取消');
									uni.navigateBack()
								}
							}
						});
					})
					.catch((err) => {
						uni.showToast({
							icon: 'none',
							title: err
						})
						uni.navigateBack()
					});
			},
			getDetail() {
				let api;
				if (this.type == 'jq') {
					api = `/order/scenicTicketBusinessOrder/detailApplectScenicOrder`
				} else if (this.type == 'act') {
					api = `/order/activityTicketBusinessOrder/detailApplectActivityOrder`
				}
				requestGet(api, {
					orderNum: this.id,
				}).then((res) => {
					if (res.code === 200) {
						const detail = res.data || {};
						detail.commonName = detail.detaildVoList[0]?.commonName;
						detail.ticketName = detail.detaildVoList[0]?.ticketName;
						detail.detaildVoList = detail.detaildVoList.map((v) => Object.assign(
							v, {
								ticketUsetimeStart: dayjs(v.ticketUsetimeStart).format(
									'MM月DD日 HH:mm'),
								ticketUsetimeEnd: dayjs(v.ticketUsetimeEnd).format(
									'MM月DD日 HH:mm')
							}));
						this.info = detail;
						if (detail.orderStatus == 4) {
							uni.showModal({
								title: '提示',
								content: '该订单已核销！',
								showCancel: false,
								success: function(res) {
									if (res.confirm) {
										console.log('用户点击确定');
										uni.navigateBack()
									} else if (res.cancel) {
										console.log('用户点击取消');
										uni.navigateBack()
									}
								}
							});
						}
					}
				});
			},
		},
	};
</script>

<style lang="scss">
	.ticket-detail-page {
		box-sizing: border-box;
		min-height: 100vh;
		background-color: #F5F7F6;
    overflow: auto;

		.wrap {
			min-height: 100vh;
			box-sizing: border-box;
			padding: 0 0 200rpx;
			// background: linear-gradient(
			//   180deg,
			//   #c1ddff 0%,
			//   rgba(193, 221, 255, 0) 600rpx,
			//   #f7f9fa 100%
			// );
		}

		.statue-title {
			font-size: 40rpx;
			font-weight: 500;
			color: rgba(0, 0, 0, 0.8);
			line-height: 56rpx;
			margin-bottom: 40rpx;
		}
    .ticket-title {
			display: flex;
      flex-direction: column;
			align-items: flex-start;
      justify-content: flex-start;
      padding: 32rpx;
      border-bottom: 2rpx solid rgba(0,0,0,0.1);
			.title {
				font-size: 28rpx;
				font-weight: 400;
				color: #87A198;
				line-height: 40rpx;
			}
      .name {
      	font-size: 32rpx;
      	font-weight: 600;
      	color: rgba(0,0,0,0.8);
      	line-height: 44rpx;
        margin: 16rpx 0;
        text:last-child{
          font-size: 28rpx;
          font-weight: 400;
          color: #3FAA73;
          line-height: 40rpx;
          margin-left: 24rpx;
        }
      }
      .ticket-validity{
        font-size: 28rpx;
        font-weight: 400;
        color: #3FAA73;
        line-height: 40rpx;
        display: flex;
        align-items: center;
        .tcan {
          font-size: 28rpx;
          font-weight: 400;
          color: rgba(0,0,0,0.5);
          line-height: 40rpx;
        	margin-left: 16rpx;
          margin-right: 16rpx;
        }
      }
		}
		.ticket-item {
			padding: 32rpx;
			.ticket-card {
				margin-bottom: 16rpx;
				padding: 24rpx;
				box-sizing: border-box;
				background: #ffffff;
				border-radius: 16rpx 16rpx 16rpx 16rpx;

				.item {
					display: flex;
					justify-content: space-between;
					align-items: center;
          height: 88rpx;
					.label {
						font-size: 28rpx;
						font-weight: 400;
						color: rgba(0,0,0,0.5);
						line-height: 40rpx;
					}
					.value {
						font-size: 28rpx;
						font-weight: 600;
						color: rgba(0,0,0,0.7);
						line-height: 40rpx;
					}
				}
			}
		}

		.pay {
			position: relative;
			margin-top: 36rpx;
			text-align: right;
			font-size: 28rpx;
			font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.7);
			line-height: 40rpx;

			text {
				font-size: 32rpx;
				font-family: D-DIN-Bold, D-DIN;
				font-weight: 700;
				color: #ff7614;
				line-height: 34rpx;
			}
		}

		.order-info-tip {
			position: absolute;
			top: 0;
			left: 0;
			display: flex;
			align-items: center;
			font-size: 28rpx;
			font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
			font-weight: 400;
			color: rgba(0, 0, 0, 0.5);
			line-height: 40rpx;

			image {
				width: 32rpx;
				height: 32rpx;
				display: block;
				margin-left: 8rpx;
			}
		}

		.card-code {
			margin-top: 24rpx;
			background: #ffffff;
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			padding: 60rpx;
			text-align: center;

			.tip {
				font-size: 32rpx;
				font-family: Alibaba PuHuiTi 2-75 SemiBold, Alibaba PuHuiTi 20;
				font-weight: 700;
				color: #3d3d3d;
				line-height: 44rpx;
			}

			.qr-code {
				margin: 24rpx auto 0;
				width: 300rpx;
				height: 300rpx;
				background: #ffffff;
			}
		}

		.card-info {
			margin-top: 32rpx;
		}

		.mt24 {
			margin-top: 24rpx;
		}

		.card-info-title {
			font-size: 32rpx;
			font-weight: 700;
			color: #3d3d3d;
			line-height: 44rpx;
		}

		.info-item {
			margin-top: 24rpx;
			background: #ffffff;
			padding: 32rpx 24rpx;
			border-radius: 24rpx 24rpx 24rpx 24rpx;

			.name {
				display: flex;
				align-items: center;
				font-size: 32rpx;
				font-weight: 400;
				color: rgba(0, 0, 0, 0.8);
				line-height: 44rpx;
			}

			.tag {
				margin-left: 10rpx;
				font-size: 24rpx;
				font-family: Alibaba PuHuiTi 2-45 Light, Alibaba PuHuiTi 20;
				font-weight: 300;
				color: #2187ff;
				line-height: 32rpx;
				background: rgba(77, 134, 247, 0.102);
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				padding: 0 8rpx;
			}

			.p {
				display: flex;
				align-items: center;

				.label {
					margin-right: 48rpx;
					font-size: 28rpx;
					font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
					font-weight: 400;
					color: #777f8f;
					line-height: 40rpx;
				}

				.label-text {
					flex: 1;
					font-size: 28rpx;
					font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
					font-weight: 400;
					color: rgba(0, 0, 0, 0.8);
					line-height: 40rpx;
				}
			}
		}

		.btns {
			position: fixed;
			bottom: 0;
			width: 100%;
			left: 0;
			height: 124rpx;
			display: flex;
			padding-bottom: constant(safe-area-inset-bottom);
			padding-bottom: env(safe-area-inset-bottom);
			align-items: center;
			justify-content: center;
			z-index: 1;
			box-sizing: border-box;
			padding: 16rpx 32rpx;

			.btn {
				box-sizing: border-box;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				padding: 0 28rpx;
				height: 88rpx;
				border: 0;
				font-size: 28rpx;
				font-family: Alibaba PuHuiTi 2-55 Regular, Alibaba PuHuiTi 20;
				font-weight: 400;
				border-radius: 100px;

				&.outline {
					border: 2rpx solid #b7c1ca;
					color: #777f8f;
				}

				&.icon-service {
					image {
						display: block;
						width: 34rpx;
						height: 34rpx;
						margin-right: 14rpx;
					}
				}

				&.w422 {
					width: 422rpx;
				}

				&.w240 {
					width: 240rpx;
				}

				&.primary {
					width: 100%;
					background: #3FAA73;
					border: 2rpx solid #3FAA73;
					color: #fff;
				}
			}
		}

		.popup-content {
			background: #f7f9fa;
			padding: 32rpx;

			.title {
				position: relative;
				font-size: 32rpx;
				font-family: Alibaba PuHuiTi 2-75 SemiBold, Alibaba PuHuiTi 20;
				font-weight: 700;
				color: #3d3d3d;
				line-height: 44rpx;
				text-align: center;

				image {
					position: absolute;
					right: 0;
					top: 0;
					z-index: 1;
					display: block;
					width: 48rpx;
					height: 48rpx;
					cursor: pointer;
				}
			}
		}
	}
</style>